import nats from "node-nats-streaming";
import { TicketCreatedPublisher } from "./events/ticket-created-publisher"

const stan = nats.connect("ticketing", "abc", {
	url: "http://localhost:4222"
});

stan.on("connect", async  () => {
	console.log("publisher 连接到 NATS:");

	const publisher = new TicketCreatedPublisher(stan);
	try{
		await publisher.publish({
			id: '123',
			title: 'test',
			price: 32
		});
	} catch(err){
		console.error(err);
	}
	

	// const data = JSON.stringify({
	// 	id: '231342342342',
	// 	title: "test",
	// 	price: 200
	// });
	// stan.publish(`ticket:created`, data, () => {
	// 	console.log("发送消息》》》》");
	// })
});
